var $audio = $('.wraper audio'),
  $palyBtn = $('.wraper .music .play'),
  $prevBtn = $('.wraper .music .prev'),
  $nextBtn = $('.wraper .music .next'),
  $inner = $('.wraper .rotate_box .inner');

var mediaObj = {
  0: './media/4st,鏡音レン - Butterfly.mp3',
  1: './media/Czarina - I Miss You.mp3',
  2: './media/沈以诚 - 越来越不懂.mp3',
  length: 3,
};

var idx = 0;

// 播放暂停
$palyBtn.on('click', function () {
  if ($audio[0].paused) {
    $(this).toggleClass('icon-bofang').toggleClass('icon-zanting');
    $audio.attr('src', mediaObj[idx])[0].play();
  } else {
    $audio[0].pause();
    $(this).toggleClass('icon-bofang').toggleClass('icon-zanting');
  }
});

// 下一曲
$nextBtn.on('click', function () {
  idx++;
  if (idx > mediaObj.length) {
    idx = 0;
  }
  $palyBtn.removeClass('icon-bofang').addClass('icon-zanting');
  $audio.attr('src', mediaObj[idx])[0].play();
  flag = true;
});

// 上一曲
$prevBtn.on('click', function () {
  idx--;
  if (idx < 0) {
    idx = mediaObj.length - 1;
  }
  $palyBtn.removeClass('icon-bofang').addClass('icon-zanting');
  $audio.attr('src', mediaObj[idx])[0].play();
  flag = true;
});

// 获取当前时间
var $timerMin = $('.wraper .music .current_timer #minutes'),
  $timerSec = $('.wraper .music .current_timer #secondes');

$audio[0].addEventListener(
  'timeupdate',
  function () {
    //监听音频播放的实时时间事件
    var currentDisplay = Math.floor($audio[0].currentTime); //获取实时时间//用秒数来显示当前播放进度

    //处理时间

    //分钟
    var currentMinutes = parseInt(currentDisplay / 60);
    if (currentMinutes < 10) {
      currentMinutes = '0' + currentMinutes;
    }
    $timerMin.text(currentMinutes);
    //秒
    var currentSeconds = Math.round(currentDisplay % 60);
    if (currentSeconds < 10) {
      currentSeconds = '0' + currentSeconds;
    }
    $timerSec.text(currentSeconds);
  },
  false
);

// 获取总的时间
var $allTimerMin = $('.wraper .music .all_timer #minutes'),
  $allTimerSec = $('.wraper .music .all_timer #secondes');

$audio[0].addEventListener(
  'timeupdate',
  function () {
    //监听音频播放的实时时间事件
    var allDisplay = Math.floor($audio[0].duration); //获取实时时间//用秒数来显示当前播放进度

    //处理时间

    //分钟
    var allMinutes = parseInt(allDisplay / 60);
    if (allMinutes < 10) {
      allMinutes = '0' + allMinutes;
    }
    $allTimerMin.text(allMinutes);
    //秒
    var allSeconds = Math.round(allDisplay % 60);
    if (allSeconds < 10) {
      allSeconds = '0' + allSeconds;
    }
    $allTimerSec.text(allSeconds);
  },
  false
);

// 歌词部分
var $irc = $('.irc textarea');
